package com.xiaoshuidi.cloud.module.iot.controller.admin.callback;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.module.iot.dal.model.callback.EmecoDeviceCallbackReqVO;
import com.xiaoshuidi.cloud.module.iot.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.iot.service.EmecoCallBackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 埃美柯水表回调部分
 */

@RestController
@RequestMapping(ApiConstants.NAME+"/callback/emeco")
public class EmecoDeviceController {

    private final Logger LOGGER = LoggerFactory.getLogger(EmecoDeviceController.class);

    @Autowired
    private EmecoCallBackService emecoCallBackService;

    /**
     * 埃美柯回调处理
     *
     * @param
     * @return
     */
    @PostMapping("cb")
    public void callback(@RequestBody String params) {
        EmecoDeviceCallbackReqVO emecoDeviceCallbackReqVO = JSONUtil.toBean(params, EmecoDeviceCallbackReqVO.class);
        LOGGER.info("埃美柯水表回调请求，请求内容:{}", JSONObject.toJSONString(emecoDeviceCallbackReqVO));
        try {
            emecoCallBackService.callback(emecoDeviceCallbackReqVO);
        } catch (Exception e) {
            LOGGER.error("埃美柯水表回调请求,请求内容：{},errorMessage:", JSONObject.toJSONString(emecoDeviceCallbackReqVO), e);
        }
    }


}
